#! /bin/sh
. ~/.bashrc

cd /home/hadoop/access

date='17-04-02'
enddate='17-04-13'

echo "------------------------------"
echo "date=$date"
echo "enddate=$enddate"
echo "------------------------------"


while [[ $date < $enddate  ]]
do
        echo $date
		
		tarFile="/home/hadoop/access/backuplog/access_20${date//-/}.tgz"
		if [ -f /home/hadoop/access/backuplog/access_20${date//-/}.tgz ];then
			tarxLog="tar -xzf $tarFile"
			echo $tarxLog
			eval $tarxLog
			copyFromLocal="/usr/local/hadoop/bin/hadoop fs -copyFromLocal ~/access/20${date//-/}/* /user/logsystem/access/20${date//-/}/"
			echo $copyFromLocal
			eval $copyFromLocal
			rmLog="rm -rf 20${date//-/}"
			echo $rmLog
			eval $rmLog
			
			for domain in `cat /home/hadoop/mylib/domain.list` ;do
                pvShell='/usr/local/hadoop/bin/hadoop jar ~/mylib/kpistats-0.0.1-jar-with-dependencies.jar com.think.PvStatistics -d '$date' -domain '$domain;
                echo $pvShell;
                eval $pvShell;
                ipShell='/usr/local/hadoop/bin/hadoop jar ~/mylib/kpistats-0.0.1-jar-with-dependencies.jar com.think.UipStatistics -d '$date' -domain '$domain;
                echo $ipShell;
                eval $ipShell;
                rmHdfsLog="/usr/local/hadoop/bin/hadoop fs -rmr /user/logsystem/access/20${date//-/}/$domain"
				echo $rmHdfsLog
				eval $rmHdfsLog
        	done
        	
        	kpiShell='/usr/local/hadoop/bin/hadoop jar ~/mylib/kpistats-0.0.1-jar-with-dependencies.jar com.think.KpiStatistics -d '$date';
            echo $kpiShell;
            eval $kpiShell;
        	
		else
        	for domain in `cat /home/hadoop/mylib/domain.list` ;do
                pvShell='/usr/local/hadoop/bin/hadoop jar ~/mylib/kpistats-0.0.1-jar-with-dependencies.jar com.think.PvStatistics -d '$date' -domain '$domain;
                echo $pvShell;
                eval $pvShell;
                ipShell='/usr/local/hadoop/bin/hadoop jar ~/mylib/kpistats-0.0.1-jar-with-dependencies.jar com.think.UipStatistics -d '$date' -domain '$domain;
                echo $ipShell;
                eval $ipShell;
        	done
        	
        	kpiShell='/usr/local/hadoop/bin/hadoop jar ~/mylib/kpistats-0.0.1-jar-with-dependencies.jar com.think.KpiStatistics -d '$date';
            echo $kpiShell;
            eval $kpiShell;
		fi
        date=`date -d "+1 day $date" +%y-%m-%d`
done
